<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- STYLESHEETS -->
    <!--[if lt IE 9]>
    <script src="../../js/flot/excanvas.min.js"></script>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
    <link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
    <link rel="stylesheet" type="text/css" href="../../css/responsive.css">

    <link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- file-input -->
    <link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css"/>
    <!-- SELECT2 -->
    <link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css"/>
    <!-- UNIFORM -->
    <link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css"/>
    <!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">
    <!-- WIZARD -->
    <link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css"/>
    <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
    <!-- FONTS
<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
    <!-- JQUERY -->
    <script src="../../js/jquery/jquery-2.0.3.min.js"></script>
    <script src="../../js/common.js"></script>
</head>

<body>
<header class="navbar clearfix" id="header">
</header>

<!-- PAGE -->
<section id="page">
    <!-- SIDEBAR -->
    <div id="sidebar" class="sidebar">
        <div class="sidebar-menu nav-collapse">

            <!-- SIDEBAR MENU -->
            <ul>

            </ul>
            <!-- /SIDEBAR MENU -->
        </div>

    </div>
    <!-- /SIDEBAR -->
    <div id="main-content">

        <div class="container">
            <div class="row">
                <div id="content" class="col-lg-12">
                    <!-- PAGE HEADER-->
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="page-header">
                                <!-- STYLER -->

                                <!-- /STYLER -->
                                <!-- BREADCRUMBS -->
                                <ul class="breadcrumb">
                                    <li>
                                        <i class="fa fa-home"></i>
                                        <a href="index.html">首页</a>
                                    </li>
                                    <li>
                                        <a href="#">商品管理</a>
                                    </li>
                                    <li>维护商品</li>
                                </ul>
                                <!-- /BREADCRUMBS -->

                            </div>
                        </div>
                    </div>
                    <!-- /PAGE HEADER -->
                    <!-- SAMPLE -->
                    <form id="form_giveaway">

                        <div class="row col-md-12">
                            <div class="box border primary" style="margin-left: 20px;">
                                <div class="box-title">
                                    <h4><i class="fa fa-bars"></i>SOURCE值赠品</h4>
                                </div>
                                <div class="box-body big" style="padding:10px;">


                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2"><span class="required">*</span>活动名称：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="activityName" onfocus="this.select()" placeholder="请输入活动名称"
                                                   maxlength="50"/>
                                            <input type="hidden" name="id"/>
                                            <input type="hidden" name="oldSourceCode"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2"><span class="required">*</span>SOURCE值：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="sourceCode" onfocus="this.select()" placeholder="请输入SOURCE值"
                                                   maxlength="50"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="padding: 10px ;height: 150px">
                                        <label class="control-label col-md-2"><span class="required">*</span>原SKU编码：</label>
                                        <div class="col-md-8 inline">
												<textarea type="text" style="width: 600px;height:100px; margin-top: 7px" class="form-control required"
                                                          name="sourceSkuCodes" placeholder="请输入SKU编码。多个以英文逗号分隔" style="color:inherit"></textarea>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2"><span class="required">*</span>购买数量：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="buyCount" onfocus="this.select()" placeholder="请输入购买数量，单个商品数量"
                                                   maxlength="50"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2"><span class="required">*</span>赠品SKU：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="giftSkuCode" onfocus="this.select()" placeholder="请输入赠品SKU"
                                                   maxlength="50"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2"><span class="required">*</span>赠送数量：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="giveCount" onfocus="this.select()" placeholder="请输入赠送商品数量。"
                                                   maxlength="50"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2"><span class="required">*</span>是否校验库存：</label>
                                        <div class="col-md-1 inline">
                                            <input type="checkbox" checked="checked" name="checkStock"/>

                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2"><span class="required">*</span>是否校验渠道：</label>
                                        <div class="col-md-1 inline">
                                            <input type="checkbox" checked="checked" name="channel"/>

                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" id="rangDate">
                                        <label class="control-label col-md-2"><span class="required">*</span>生效日期：</label>
                                        <div class="col-md-6 inline" style="display:inline-flex">
                                            <input type="text" class="form-control width-50 bootstrap-datepicker" name="startDate" style="width:110px"/>-
                                            <input type="text" class="form-control width-50 bootstrap-datepicker" name="endDate" style="width:120px"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2">操作人：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="handler" onfocus="this.select()" readonly="readonly"
                                                   maxlength="50"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="form-group mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-2">操作时间：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50 bootstrap-datepicker" readonly="readonly" name="updateTime"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>

                                </div>

                            </div>
                        </div>
                    </form>
                    <div class="row" style="height: 30px;">
                        <div class="col-md-12" style="text-align: center;">
                            <div class="box ">
                                <a href="#" class="btn btn-success config bt-submit" style="width: 100px">
                                    保存
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <!-- /SAMPLE -->

            <div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
            </div>
        </div>
        <!-- /CONTENT-->
    </div>
    </div>
    </div>
</section>
<!--/PAGE -->
<!-- JAVASCRIPTS -->
<!-- Placed at the end of the document so the pages load faster -->

<!-- BOOTSTRAP -->
<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

<!-- BLOCK UI -->
<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
<!--bootbox-->
<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
<!-- AUTOSIZE -->
<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
<!-- spinner -->
<script src="../../js/spinner/spin.js"></script>
<!-- INPUT MASK -->

<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
<!-- UNIFORM -->
<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
<!-- DATA TABLES -->
<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>


<!-- SELECT2 -->
<script type="text/javascript" src="../../js/select2/select2.min.js"></script>

<script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
<!-- COOKIE -->
<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
<!-- CUSTOM SCRIPT -->
<script src="../../js/script.js"></script>

<script src="../../js/Sortable.min.js"></script>
<script>
    var AddGiveaway = function () {
        var gaform = $('#form_giveaway');
        var id, flag;
        var formValiInit = function () {
            gaform.validate({
                doNotHideMessage: true,
                errorClass: 'error-span',
                errorElement: 'span',
                rules: {
                    activityName: {
                        required: true
                    },
                    sourceCode: {
                        required: true
                    },
                    skuCode: {
                        required: true
                    }
                },
                highlight: function (element) {
                    $(element)
                        .closest('.form-group').removeClass('has-success').addClass('has-error');
                },

                unhighlight: function (element) {
                    $(element)
                        .closest('.form-group').removeClass('has-error');
                },
                success: function (label) {
                    if (label.attr("for") == "gender") {
                        label.closest('.form-group').removeClass('has-error').addClass('has-success');
                        label.remove();
                    } else {
                        label.addClass('valid')
                            .closest('.form-group').removeClass('has-error').addClass('has-success');
                    }
                }
            });
        };

        var saveSingleGift = function () {
            if (gaform.valid() == false) return false;
            var singleGift = {};
            singleGift.activityName = $("input[name=activityName]").val();
            singleGift.sourceCode = $("input[name=sourceCode]").val();
            singleGift.sourceSkuCodes = $("[name=sourceSkuCodes]").val();
            singleGift.giftSkuCode = $("input[name=giftSkuCode]").val();
            singleGift.startDate = $("input[name=startDate]").val();
            singleGift.endDate = $("input[name=endDate]").val();
            singleGift.buyCount = $("input[name=buyCount]").val();
            singleGift.giveCount = $("input[name=giveCount]").val();
            singleGift.checkStock = $("[name=checkStock]").prop("checked");
            singleGift.channel = $("[name=channel]").prop("checked");


            $.blockUI();
            var url = App.getContextPath() + "admin/activity/saveSingleGift.do";

            $.ajax({
                type: "post",
                url: url,
                data: $.param({singleGift: JSON.stringify(singleGift)}),
                async: true,
                success: function (result) {
                    console.log(result);
                    $.unblockUI();
                    if (result.type == "error") {
                        $.alert(result.content);
                    } else {
                        $.alert("保存成功");
                        // getSingleGift(singleGift.sourceCode);
                    window.location.href="single_gift_list.html";
                    }
                }
            });
        };


        //获取SOURCE值赠品详情
        var getSingleGift = function (sourceCode, isChannel) {
            $.ajax({
                type: "post",
                url: App.getContextPath() + "admin/activity/getSingleGift.do",
                data: {sourceCode: sourceCode, isChannel: isChannel},
                async: true,
                success: function (result) {
                    result = result.extra;
                    if (result) {

                        $("[name=activityName]").val(result.activityName);
                        $("[name=sourceCode]").val(result.sourceCode);
                        $("[name=sourceSkuCodes]").val(result.sourceSkuCodes);
                        $("[name=giftSkuCode]").val(result.giftSkuCode);
                        $("[name=handler]").val(result.handler);
                        $("[name=buyCount]").val(result.buyCount);
                        $("[name=giveCount]").val(result.giveCount);
                        $("[name=updateTime]").val(new Date(parseInt(result.updateTime)).format("yyyy-MM-dd hh-mm-ss"));
                        if (!result.checkStock) {
                            $("[name=checkStock]").removeAttr('checked');
                        }
                        if (!result.channel) {
                            console.log(result.channel)
                            $("[name=channel]").removeAttr('checked');
                        }

                        $("[name=startDate]").val(new Date(parseInt(result.startDate)).format("yyyy-MM-dd"));
                        $("[name=endDate]").val(new Date(parseInt(result.endDate)).format("yyyy-MM-dd"));
                    }
                }
            });
        };


        return {
            init: function () {
                App.init();
                formValiInit();
                $.initDate($("#rangDate"), 0, 15);
                $("input[name=startDate]").bsdatepicker("setValue", $.nowDate());
                $(".bt-submit").click(saveSingleGift);
                var sourceCode = $.getUrlParam("sourceCode");
                var isChannel = $.getUrlParam("isChannel");
                if (sourceCode) {
                    getSingleGift(sourceCode, isChannel);
                }

            }
        }
    }();
    $(function () {
        $("#header").load("../head.html");
        AddGiveaway.init();
    });
</script>

<!-- /JAVASCRIPTS -->
</body>

</html>